package com.ls.blog.controller;

import com.ls.blog.result.JsonResult;
import com.ls.blog.utils.QianNiuUpload;
import com.ls.blog.utils.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-11 16:04
 **/
@Api(tags = {"文件上传模块"})
@RestController
@RequestMapping("upload")
public class UploadController {

    @ApiOperation(value = "图片上传")
    @PostMapping()
    public JsonResult upload(@RequestPart("image")MultipartFile file){

        String url = QianNiuUpload.uploadFile(file);
        if (url!=null){
            return ResultTool.success(url);
        }
        return ResultTool.fail();
    }
}
